#include <IOExpander.h>

IOExpander IOexp;

uint8_t *chipOut=IOexp.IO_CHIPB;
uint8_t puertoOut=IOexp.IO_PORTB;

/*
//Sustituye los anteriroes por estos para probar el chip A y puerto A
//Replace before definitions by the below values, for test de chip A and port A
uint8_t *chip=IOexp.IO_CHIPA;
uint8_t puerto=IOexp.IO_PORTA;


//Sustituye los anteriroes por estos para probar el chip A y puerto B
//Replace before definitions by the below values, for test de chip A and port B
uint8_t *chip=IOexp.IO_CHIPA;
uint8_t puerto=IOexp.IO_PORTB;


//Sustituye los anteriroes por estos para probar el chip B y puerto A
//Replace before definitions by the below values, for test de chip B and port A
uint8_t *chip=IOexp.IO_CHIPB;
uint8_t puerto=IOexp.IO_PORTA;


//Sustituye los anteriroes por estos para probar el chip B y puerto B
//Replace before definitions by the below values, for test de chip B and port B
uint8_t *chip=IOexp.IO_CHIPB;
uint8_t puerto=IOexp.IO_PORTB;
*/
  
void setup(){
  IOexp.begin(7,0);
  IOexp.portMode(chipOut, puertoOut, IOexp.ioOUTPUT);  
}

void loop(){
  for(int j=0;j<3;j++){
    for(int i=0;i<8;i++){
      //delay(2);
      IOexp.digitalWrite(chipOut, puertoOut, i, 1);
      delay(50);
      IOexp.digitalWrite(chipOut, puertoOut, i, 0);
    }
  }
  
  for(int j=0;j<3;j++){
    for(int i=7;i>=0;i--){
      //delay(2);
      IOexp.digitalWrite(chipOut, puertoOut, i, HIGH);
      delay(50);
      IOexp.digitalWrite(chipOut, puertoOut, i, LOW);
    }
  }
  
  for(int j=0;j<6;j++){
    
    for(int i=0;i<8;i++){
      //delay(2);
      IOexp.digitalWrite(chipOut, puertoOut, i, 1);
      delay(50);
      IOexp.digitalWrite(chipOut, puertoOut, i, 0);
    }
    for(int i=7;i>=0;i--){
      //delay(2);
      IOexp.digitalWrite(chipOut, puertoOut, i, (unsigned char)1);
      delay(50);
      IOexp.digitalWrite(chipOut, puertoOut, i, (unsigned char)0);
    }
  }
      IOexp.digitalWritePort(chipOut, puertoOut, 0);
      delay(50);
  for(int j=0;j<5;j++){
      IOexp.digitalWritePort(chipOut, puertoOut, 255);
      delay(100);
      IOexp.digitalWritePort(chipOut, puertoOut, 0b00000000);
      delay(100);
      IOexp.digitalWritePort(chipOut, puertoOut, 0xff);
      delay(100);
      IOexp.digitalWritePort(chipOut, puertoOut, 0x00);
      delay(300);
  }
  
}
